<?php
/**
 * Created by PhpStorm.
 * User: alei
 * Date: 11/11/2017 AD
 * Time: 14:42
 */
namespace App\Models\Mysql;

//use Illuminate\Database\Eloquent\Model;
use App\Models\Traits\BaseDBMethod;

class pre_forum_attachment
{
	use BaseDBMethod;
	//数据库连接配置项，见config/database.php
	const DATABASE_CONF = 'lqyw_mysql';
	//pre_ct_ui 首页轮播图所在表
	const TABLE_NAME = 'pre_forum_attachment';

	//数据库连接配置项，见config/database.php
	//如果需要用ORM，需要设置此项
//	protected $connection = self::DATABASE_CONF;
	//表名，如果需要用ORM，需要设置此项
//	protected $table = self::TABLE_NAME;

	public static function getAttachment($aid)
	{
		$r = self::getConnObj()->select("select tableid from pre_forum_attachment where aid=".$aid);
		if (empty($r)){
			return $r;
		}
		$tableName = "pre_forum_attachment_".(($r[0]->tableid==127)?'unused':$r[0]->tableid);
		$r2 = self::getConnObj()->select("select attachment,width from ".$tableName." where isimage=1 and aid=".$aid);
		return (empty($r2)) ? $r2 : $r2[0];
	}

} //end pre_forum_forum
